package com.lzh.hash;

import java.util.Scanner;

/**
 * @author liuzhihao
 * @create 2022-08-07 17:51
 *
 * 控制台用来测试
 */
public class Console {

    public static void main(String[] args) {
        Student student1 = new Student(1, "tom");
        Student student2 = new Student(2, "alice");
        Student student3 = new Student(3, "kitty");
        Student student4 = new Student(4, "aaaa");
        Student student5 = new Student(5, "bbbb");
        Student student6 = new Student(6, "cccc");
        Student student7 = new Student(7, "dddd");
        Student student8 = new Student(8, "eeee");
        Student student9 = new Student(9, "ffff");
        Student student10 = new Student(10, "gggg");
        Student student11 = new Student(11, "hhhh");
        Student student12 = new Student(12, "ggggg");

        HashTableSelf hashTableSelf = new HashTableSelf(7);
        hashTableSelf.add(student1);
        hashTableSelf.add(student2);
        hashTableSelf.add(student3);
        hashTableSelf.add(student4);
        hashTableSelf.add(student5);
        hashTableSelf.add(student6);
        hashTableSelf.add(student7);
        hashTableSelf.add(student8);
        hashTableSelf.add(student9);
        hashTableSelf.add(student10);
        hashTableSelf.add(student11);
        hashTableSelf.add(student12);
        hashTableSelf.list();

        System.out.println("==================");
//        hashTableSelf.update(155, "liuzhihao");
//        hashTableSelf.list();

        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.println("======请输入您的操作======");
            System.out.println("add:    添加学生");
            System.out.println("del:    添加学生");
            System.out.println("update: 添加学生");
            System.out.println("list:   查询所有");
            System.out.println("exit：  退出系统");
            String input = scanner.next();
            switch (input) {
                case "add":
                    System.out.print("请输入添加学生的id:");
                    int inputId = scanner.nextInt();
                    System.out.print("请输入添加学生的name:");
                    String inputName = scanner.next();
                    Student inputStudent = new Student(inputId, inputName);
                    hashTableSelf.add(inputStudent);
                    break;
                case "del":
                    System.out.print("请输入要删除学生的id：");
                    int delId = scanner.nextInt();
                    hashTableSelf.del(delId);
                    break;
                case "update":
                    System.out.println();
                    System.out.print("请输入添加学生的id:");
                    int updateId = scanner.nextInt();
                    System.out.print("请输入添加学生的name:");
                    String updateName = scanner.next();
                    hashTableSelf.update(updateId, updateName);
                    break;
                case "list":
                    hashTableSelf.list();
                    break;
                case "exit":
                    System.out.println("退出系统成功！");
                    scanner.close();
                    System.exit(0);
                default:
                    System.out.println("请正确输入操作");
                    break;
            }

        }

    }

}
